<template>
  <main class="page-container">
    <!-- 顶部Banner -->
    <section class="banner-section">
      <a target="_blank" href="/" class="banner-link">
        <img
            src="~/assets/images/banner.jpg"
            alt="平台推广"
            class="banner-img"
            loading="lazy"
        />
      </a>
    </section>

    <!-- 公告与数据概览 -->
    <section class="info-bar">
      <div class="container">
        <!-- 最新公告 -->
        <div class="announcement">
          <div class="announcement-title">
            <i class="icon-bell"></i>
            <span>最新公告</span>
          </div>
          <div class="announcement-content">
            <div class="scroll-container">
              <ul class="announcement-list" ref="announcementList">
                <li v-for="(item, index) in announcements" :key="index">
                  <a
                      :href="item.url"
                      target="_blank"
                      class="announcement-link"
                      :title="item.title"
                  >
                    {{ item.title }}
                  </a>
                </li>
              </ul>
            </div>
          </div>
          <a href="/announcements" class="more-link">更多</a>
        </div>

        <!-- 运营数据 -->
        <div class="stats">
          <div class="stat-item">
            <div class="stat-label">累计投资金额</div>
            <div class="stat-value">
              <strong>{{ totalInvestment }}</strong>
              <span class="unit">元</span>
            </div>
          </div>
          <div class="stat-item">
            <div class="stat-label">累计注册人数</div>
            <div class="stat-value">
              <strong>{{ totalUsers }}</strong>
              <span class="unit">人</span>
            </div>
          </div>
        </div>
      </div>
    </section>

    <!-- 平台优势 -->
    <section class="features-section">
      <div class="container">
        <div class="features-grid">
          <a href="#" class="feature-card" :class="`feature-${index+1}`" v-for="(feature, index) in features" :key="index">
            <div class="feature-icon">
              <i :class="feature.icon"></i>
            </div>
            <h3 class="feature-title">{{ feature.title }}</h3>
            <p class="feature-desc">{{ feature.description }}</p>
          </a>
        </div>
      </div>
    </section>
  </main>
</template>

<script>
import '~/assets/css/index.css'

export default {
  data() {
    return {
      // 公告数据
      announcements: [
        { title: "2020年9月8日还款公告", url: "公司公告详细.html" },
        { title: "关于平台中秋假期运营安排的通知", url: "#" },
        { title: "平台2020年第二季度运营报告发布", url: "#" },
        { title: "新用户注册福利活动上线通知", url: "#" }
      ],
      // 运营数据
      totalInvestment: "1,047,288,128.79",
      totalUsers: "20,649",
      // 平台优势
      features: [
        {
          title: "高收益",
          description: "年化收益率最高达20%，50元起投，助您轻松获收益",
          icon: "icon-high-yield"
        },
        {
          title: "安全理财",
          description: "100%本息保障，实物质押，多重风控审核",
          icon: "icon-security"
        },
        {
          title: "随时赎回",
          description: "两步赎回您的资金，最快当日到账",
          icon: "icon-redemption"
        },
        {
          title: "随时随地理财",
          description: "下载手机客户端，随时随地轻松理财",
          icon: "icon-mobile"
        }
      ],
      scrollTimer: null
    };
  },
  mounted() {
    // 启动公告滚动
    this.startAnnouncementScroll();
  },
  beforeUnmount() {
    // 清除定时器
    if (this.scrollTimer) {
      clearInterval(this.scrollTimer);
    }
  },
  methods: {
    // 公告滚动效果
    startAnnouncementScroll() {
      const list = this.$refs.announcementList;
      if (!list) return;

      let scrollTop = 0;
      const itemHeight = 30; // 每条公告高度
      const totalHeight = this.announcements.length * itemHeight;
      const visibleHeight = 30; // 可见区域高度

      this.scrollTimer = setInterval(() => {
        scrollTop += 1;
        // 滚动到最后一条时重置
        if (scrollTop >= totalHeight - visibleHeight) {
          scrollTop = 0;
        }
        list.style.transform = `translateY(-${scrollTop}px)`;
      }, 50);
    }
  }
};
</script>

<style scoped>

</style>